package com.ct.gd.passport.common.mock;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class ConnectRequest {

	public int id;
	public String url;
	public String method = "GET";
	protected List<? extends NameValuePair> content = new ArrayList<BasicNameValuePair>();
	
	public String getUrl() {
		if (method.equals("POST")) {
			return url;
		} else {
			StringBuffer buf = new StringBuffer();
			buf.append(url).append('?').append(getContent());
			return buf.toString();
		}
	}
	
	public List<? extends NameValuePair> getParams(){
		return content;
	}
	
	public String getContent(){
		StringBuffer buf = new StringBuffer();
		int size = content.size();
		if (size > 0) {
			for (int i = 0; i < size; i++) {
				NameValuePair nvp = content.get(i);
				buf.append(nvp.getName()).append('=').append(nvp.getValue());
				buf.append('&');
			}
			if(buf.length()>0){
				buf.setLength(buf.length()-1);
			}
		}
		return buf.toString();
	}

	@SuppressWarnings("unchecked")
	public void addParams(String key, String value){
		((ArrayList<BasicNameValuePair>)content).add(new BasicNameValuePair(key, value));
	}

}
